package com.csl.jsonpreference.test

import com.csl.jsonpreference.tag.Configurable
import com.google.gson.Gson
import org.json.JSONObject

/**
 * aqua car 设备本地配置.
 */
@Configurable(discribe = "wifi串口配置")
class WifiSerialConfig  {

    companion object {
        fun createForJson(json: JSONObject): WifiSerialConfig {
            var config: WifiSerialConfig =
                Gson().fromJson(json.toString(), WifiSerialConfig::class.java)
            config.type = SerialType.getTypeForCode(json.optInt("type"))
            return config
        }
    }

    @Configurable(discribe = "串口类型", index = 0)
    var type: SerialType = SerialType.SOFTWARE_SERIAL

    @Configurable(discribe = "是否启用", index = 1)
    var enable: Boolean = false

    @Configurable(discribe = "识别为命令\n(true不转发tcp)", index = 2)
    var aquaInput: Boolean = false

    @Configurable(discribe = "波特率", index = 3)
    var baud: Int = 9600

    @Configurable(discribe = "RX", index = 4)
    var rx: Int = 0

    @Configurable(discribe = "TX", index = 5)
    var tx: Int = 0




    override fun toString(): String {
        return "WifiSerialConfig(enable=$enable, baud=$baud, rx=$rx, tx=$tx)"
    }


}